home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-02 / buffr2.zip / BHEAPS.PAS < prev    next >
Pascal/Delphi Source File  |  1993-01-04  |  3KB  |  98 lines

  1. Unit BHeaps;
  2.  
  3. { Demonstrates the definition of a Buffered Generic Heap instantiated }
  4. { to 6 byte real numbers.                                             }
  5.  
  6. INTERFACE
  7. Uses BGenHeap,SrtFuncs;
  8.  
  9. { All Heaps additionally inherit the following Methods:
  10.  
  11.   (* BufferedArray Methods *)
  12.                              Procedure Create;
  13.                              Procedure Store;
  14.  
  15.                              Procedure Destroy;
  16.  
  17.                              Function MaxSize;
  18.                              Function ElemSize;
  19.  
  20.   (* BGenericHeap Methods *)
  21.                              Procedure Swap (I,J : LongInt);
  22.                              Procedure SiftDown (I,J : LongInt);
  23.                              Procedure BuidHeap;
  24.                              Procedure ChangeSort (NewSort : SortFunc);
  25.                              Procedure Sort;
  26.                              Procedure HeapSort;
  27. }
  28.  
  29. Type
  30.   RealHeap = Object (BGenericHeap)
  31.  
  32.                    { Re-Defining these methods re-introduces Types and }
  33.                    { most importantly, Type-Checking to the Generic    }
  34.                    { (typeless) Heap, as well as making the calls more }
  35.                    { "natural" for the actual applications Heaps.      }
  36.  
  37.                    { Follow this pattern when defining your descendant Heaps }
  38.  
  39.                    Procedure Init (MaxElements,MaxBuffSize : LongInt;
  40.                                    FileName : String);
  41.  
  42.                    Procedure Load (FileName : String; MaxBuffSize : LongInt);
  43.  
  44.                    Procedure Accept (I : Real; Index : LongInt);
  45.  
  46.                    Function Retrieve (Index : LongInt) : Real;
  47.  
  48.                             { Retrieve will nead to be a procedure for
  49.                               records or objects. }
  50.  
  51.                    Procedure SiftUp (I : Real; Index : LongInt);
  52.  
  53.                    Procedure Copy (From : RealHeap);
  54.             End;
  55.  
  56. IMPLEMENTATION
  57.  
  58. Procedure RealHeap.Init;
  59. Begin
  60.   BGenericHeap.Init (MaxElements,SizeOf(Real),MaxBuffSize,FileName,SortReal)
  61. End;
  62.  
  63. Procedure RealHeap.Load (FileName : String; MaxBuffSize : LongInt);
  64. Begin
  65.   BGenericHeap.Load (FileName,SizeOf(Real),MaxBuffSize)
  66. End;
  67.  
  68. Procedure RealHeap.Accept;
  69. Var
  70.   J : Real;
  71. Begin
  72.   J := I;
  73.   BGenericHeap.Accept (J,Index,SizeOf(Real))
  74. End;
  75.  
  76. Function RealHeap.Retrieve;
  77. Var
  78.   J : Real;
  79. Begin
  80.   BGenericHeap.Retrieve (J,Index,SizeOf(Real));
  81.   Retrieve := J
  82. End;
  83.  
  84. Procedure RealHeap.SiftUp;
  85. Var
  86.   J : Real;
  87. Begin
  88.   J := I;
  89.   BGenericHeap.SiftUp (J,Index,SizeOf(Real))
  90. End;
  91.  
  92. Procedure RealHeap.Copy (From : RealHeap);
  93. Begin
  94.   BGenericHeap.Copy (From)
  95. End;
  96.  
  97. BEGIN
  98. END.